/**   
 * @Title: LotteryRecordCommunicater.java 
 * @Package: com.esun.rabbit2.communicaters 
 * @Description: (购彩记录的通讯类) 
 * @Author: Billy qigs@500wan.com   
 * @Date: 2011-6-25 下午04:05:26  
 * Copyright (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.communicaters;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

import com.esun.config.BussinessCode;
import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.model.LotteryRecordInfo;
import com.esun.model.UserInfo;
import com.esun.network.ServerCommunicater;
import com.esun.util.log.EDebug;

/**
 * @ClassName: LotteryRecordCommunicater
 * @Description: (购彩记录的通讯类)
 * @Author: Billy qigs@500wan.com
 * @Date: 2011-6-25 下午04:05:26
 */
public class LotteryRecordCommunicater extends ServerCommunicater {
	//CK
	private final String USERSESSION = UserInfo.getUserInfo().getUserSession();
//	private String msgServer;
//
//	public String getMsgServer() {
//		return msgServer;
//	}
//
//	public void setMsgServer(String msgServer) {
//		this.msgServer = msgServer;
//	}
	
	/**
	 * 获取购彩记录
	 * @param lotid
	 * @param pageno
	 * @return
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws ParserConfigurationException
	 * @throws SAXException
	 */
	public boolean isGetLotteryRecord(String lotid, String pageno) throws ClientProtocolException, IOException, ParserConfigurationException, SAXException {
		boolean isSucceed = false;
		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		list.add(mapItem(BussinessCode.PASER_MID, BussinessCode.MID_LOTRECORD_LIST));
		list.add(mapItem(BussinessCode.PASER_CK, USERSESSION));
		list.add(mapItem(Key.KEY_LOTID, lotid));
		list.add(mapItem(Key.KEY_PAGENO, pageno));
		list.add(mapItem(Key.KEY_PAGESIZE, Config.PAGE_SIZE));

		super.getServerResponse(list, true);
//		setMsgServer(super.getServerMsg());
		if (super.getState() == 100) {
			isSucceed = true;
		}
		return isSucceed;
	}
	
	/**
	 * 将购彩记录详情放入信息类
	 * @return
	 */
	public ArrayList<LotteryRecordInfo> getLotteryRecord() {
		int count = super.getListResult().size();
		ArrayList<LotteryRecordInfo> list = new ArrayList<LotteryRecordInfo>();
		for (int i = 0; i < count; i++) {
			LotteryRecordInfo lotteryRecordInfo = new LotteryRecordInfo();
			String[] strDate = super.getListResult().get(i).get(Key.KEY_ADDTIME).split(Config.ONESPACE);
			lotteryRecordInfo.setLotteryDate(strDate[0]);
			lotteryRecordInfo.setLotteryExcept(super.getListResult().get(i).get(Key.KEY_EXPECT));
			lotteryRecordInfo.setLotID(super.getListResult().get(i).get(Key.KEY_LOTTYPE));
			lotteryRecordInfo.setLotterTime(strDate[1]);
			lotteryRecordInfo.setPayMoney(super.getListResult().get(i).get(Key.KEY_PAYMONEY).substring(0, super.getListResult().get(i).get(Key.KEY_PAYMONEY).indexOf('.') + 3));
			lotteryRecordInfo.setPlayName(super.getListResult().get(i).get(Key.KEY_PLAYNAME));
			lotteryRecordInfo.setGetMoney(super.getListResult().get(i).get(Key.KEY_GETMONEY).substring(0, super.getListResult().get(i).get(Key.KEY_GETMONEY).indexOf('.') + 3));
			lotteryRecordInfo.setID(super.getListResult().get(i).get(Key.KEY_ID));
			lotteryRecordInfo.setProID(super.getListResult().get(i).get(Key.KEY_PROID));
			lotteryRecordInfo.setLotteryState(super.getListResult().get(i).get(Key.KEY_LOTTERYSTATE));
			EDebug.o(this, "lotterystate====" + super.getListResult().get(i).get(Key.KEY_LOTTERYSTATE));
			lotteryRecordInfo.setIssuc(super.getListResult().get(i).get(Key.KEY_ISSUC));
			lotteryRecordInfo.setLotName(super.getListResult().get(i).get(Key.KEY_LOTNAME));
			lotteryRecordInfo.setPlayId(super.getListResult().get(i).get(Key.KEY_WTYPE));
			lotteryRecordInfo.setIsHeMai(super.getListResult().get(i).get(Key.KEY_ISHM));
			lotteryRecordInfo.setUID(super.getListResult().get(i).get(Key.KEY_UID));
			lotteryRecordInfo.setOpenCode(super.getListResult().get(i).get(Key.KEY_OPENCODE));
			lotteryRecordInfo.setFauserName(super.getListResult().get(i).get(Key.KEY_FAUSERNAME));

			list.add(lotteryRecordInfo);
		}

		return list;
	}

	private HashMap<String, String> mapItem(String name, String value) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put(name, value);
		return map;
	}
}
